package com.zwj.learning.timetable.controller;

import com.alibaba.excel.EasyExcel;
import com.zwj.learning.timetable.service.TimetableExcelService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("/timetableExcel")
public class TimetableExcelController {

    @Resource
    private TimetableExcelService timetableExcelService;

    /**
     * 文件上传
     * <p>1. 创建excel对应的实体对象 参照
     * <p>2. 由于默认一行行的读取excel，所以需要创建excel一行一行的回调监听器，参照
     * <p>3. 直接读即可
     */
    @PostMapping("/upload/{semesterId}")
    @ResponseBody
    public String upload(MultipartFile file,
                         @PathVariable Integer semesterId) throws IOException {

        timetableExcelService.upload(file, semesterId);
        return "success";
    }
}
